﻿<?php
/*路由处理*/
class aRouter {
    public static function init($config) {
        self::fliterquery($config);
        self::fliterdomain($config);
    }
    
    // 域名访问限制
    private static function fliterdomain($config) {
        global $APP;
        if (isset($_SERVER['HTTP_HOST'])) {
            $thisDomain = $_SERVER['HTTP_HOST'];
        } elseif(isset($_SERVER['SERVER_NAME'])) {
            $thisDomain = $_SERVER['SERVER_NAME'];
        } else {
            $thisDomain = '';
        }
        
        if (isset($config['limitdomain']) && in_array($thisDomain,$config['limitdomain']) && $config['limitdomain'][$APP['name']] != $thisDomain) {
            exit('无法访问');
        }
    }
    
    // URL参数过滤
    private static function fliterquery($config) {
        global $APP;
        // rebuild APP info if error
        if (strpos($_SERVER['REQUEST_URI'],'appname=') !== false) {
            preg_match("~\/(|index.php)\?appname=(\w+)~",$_SERVER['REQUEST_URI'],$tmp);
            if ($tmp['2'] && $tmp['2'] != $APP['name']) {
                $APP['name'] = $tmp['2'];
                $APP['config'] = __CONFIG($tmp['2']); // 获取应用的配置信息
            }
        }
    }

}

?>